package com.tanhua.server.controller;

import com.tanhua.model.mongo.Voice;
import com.tanhua.model.vo.VoiceVo;
import com.tanhua.server.service.PeachblossomService;
import org.checkerframework.framework.qual.FromStubFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 桃花传音业务，主要包含语音接收和语音发送
 */

@RestController
@RequestMapping("/peachblossom")
public class PeachblossomController {

    @Autowired
    private PeachblossomService peachblossomService;


    @PostMapping//发送语音
    public ResponseEntity sendVoice(MultipartFile soundFile) throws IOException {
        //1.接收参数，前端传递的是一个文件类型的参数
        //2.调用service处理
        peachblossomService.sendVoice(soundFile);
        //3.返回参数，这里前端不需要参数
        return ResponseEntity.ok(null);
    }

    @GetMapping//桃花传音，接收语音
    public ResponseEntity acceptVoice(){
        //1.无需参数，不用接收
        //2.调用service
        VoiceVo vo=peachblossomService.acceptVoice();
        //3.返回参数,这里需要一个vo对象
        return  ResponseEntity.ok(vo);
    }
}
